# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=mobsf
pkgver=v4.4.2.r4.g9b6e0f0
pkgrel=1
epoch=2
pkgdesc='An intelligent, all-in-one open source mobile application (Android/iOS) automated pen-testing framework capable of performing static, dynamic analysis and web API testing.'
arch=('any')
groups=('blackarch' 'blackarch-mobile')
url='https://github.com/MobSF/Mobile-Security-Framework-MobSF'
license=('GPL-3.0-or-later')
depends=('python' 'gunicorn' 'python-xmlsec')
makedepends=('git' 'python-setuptools' 'python-setuptools-scm' 'python-pip')
source=("$pkgname::git+https://github.com/MobSF/Mobile-Security-Framework-MobSF.git")
sha512sums=('SKIP')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i '/^xmlsec = "1.3.14"/d' pyproject.toml
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/"{bin,share/$pkgname}
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" *.md

  rm -rf LICENSE .gitignore docker-compose.yml Dockerfile *.bat \
    *.sh scripts/*.bat

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
source /usr/share/$pkgname/venv/bin/activate
exec gunicorn -b 0.0.0.0:8000 mobsf.MobSF.wsgi:application \
  --workers=1 --threads=10 --timeout=3600
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

